<!DOCTYPE html>
<html>
<head>
<base href="${basePath}">
<meta charset="UTF-8">
<title>搜索班级</title>
$!{include("import_js_css.html")}
$!{include("import_tab_switch.html")}
<style type="text/css">
tr th {
	text-align: center;
	vertical-align: middle;
}

tr td {
	text-align: center;
	vertical-align: middle;
}
</style>
<script type="text/javascript">
$(function() {
	
	$("#inputClassType").select2({
		width: "100%",
		minimumResultsForSearch: -1
	});
	$("#inputClassState").select2({
		width: "100%",
		minimumResultsForSearch: -1
	});
	
	
	
	//查询条件回显
	$("#inputClassName").val("${name}");
	$("#inputProduct").select2("val", "${productId}");
	$("#inputClassState").select2("val", "${state}");
	$("#inputMainTeacher").select2("val", "${mainTeacher}");
	$("#inputClassAssignedTo").select2("val", "${assignedTo}");
	$("#inputPlacement").select2("val", "${placement}");
	$("#inputClassType").select2("val", "${classType}");
	
	
	//全选反选
	$("#chkallIds").click(function() {
		$(":input[name='chk_name']").prop("checked",$(this).prop("checked"));
	});
	
	//添加
	$("#btn_add").click(function(){
		window.location.href = "yueyogaAdmin/toAddClass.jhtml";
	});

	//修改
	$("#btn_edit").click(function() {
		var chks = $('input[name="chk_name"]:checked');
		if(chks.length == 1) {
			window.location.href = "yueyogaAdmin/toUpdateClass.jhtml?classId=" + chks.val();
		} else {
			alert("请选择一条记录进行修改");
		}
	});
	
	//删除
	$("#btn_delete").click(function() {
		var chks = $('input[name="chk_name"]:checked');
		
		if(chks.length > 0) {
			confirm("确定要删除吗", function() {
				this.close();
				var url = "yueyogaAdmin/deleteClass.jhtml";
				var d = wait("正在删除，请稍候...");
				
				var ids = [];
				chks.each(function(index,item){
					ids.push($(item).val());
				});
				
				$.post(url,  {"ids":ids},  function(msg) {
					if (msg == "success") {
						d.content("删除成功");
						setTimeout(function(){
							d.close().remove();
							$(':input[name="chk_name"]').prop("checked",false);
							document.classForm.submit();
						}, 1000);
					} else {
						d.close();
						error("删除失败");
					}
				});
			});
		} else {
			alert("请选择要删除的记录");
		}
	});
	
	//添加会员
	$("#btn_addMember").click(function(){
		var chks = $('input[name="chk_name"]:checked');
		if(chks.length == 1) {
			var tr = chks.parent().parent();
			var state = $("td:eq(3)",tr).text();
			if(state == "不定会员") {
				alert("只有类型为“固定会员”的班级才可以添加会员");
				return;
			}
			window.location.href = "yueyogaAdmin/viewClass.jhtml?classId=" + chks.val() +"&tabIndex=memberInfo";
		} else {
			alert("请选择一条记录进行添加会员");
		}
	});
	
	$("#btn_addProduct").click(function(){
		var chks = $('input[name="chk_name"]:checked');
		if(chks.length == 1) {
			window.location.href = "yueyogaAdmin/viewClass.jhtml?classId=" + chks.val() +"&tabIndex=productInfo";
		} else {
			alert("请选择一条记录进行添加产品");
		}
	});
	
	//导出班级
	$("#btn_product_export").click(function(){
		var oldUrl = $("form[name=classForm]").attr("action");
		var exprotUrl = "yueyogaAdmin/exportClass.jhtml";
		$("form[name=classForm]").attr("action", exprotUrl);
		$("form[name=classForm]").submit();
		$("form[name=classForm]").attr("action", oldUrl);
	});
	
});
</script>
</head>

<body>
	$!{include("header.html")}
	<div class="container menu_all">
		<div class="tabbable tabs-left panel-db-cdt" id="div_ul_tab">
			$!{include("tab.html")}
			<div class="tab-content panel-radius-search-all panel-search">
				<div class="tab-pane active panel-search-cdts" id="panel-member">
					<div>
						<form name="classForm" class="form-horizontal" action="yueyogaAdmin/searchClass.jhtml" method="post">
							<div class="form-group">
								<label for="inputClassName" class="col-sm-1 control-label">名称</label>
								<div class="col-sm-3">
									<input name="name" type="text" class="form-control" id="inputClassName" value="${name}">
								</div>
									<label for="inputProduct" class="col-sm-1 control-label">产品</label>
								<div class="col-sm-3">
									<select id="inputProduct" data-live-search="true"
										class="selectpicker show-tick" data-width="100%" name="productId">
										<option value=""> </option>
										<option value="0">全部</option>
										<!-- #for(Product product : plProduct) -->
										<option value="${product.productId}">${product.name}</option>
										<!-- #end -->
									</select>
								</div>
								<br /> <br />
								
								<label for="inputClassState" class="col-sm-1 control-label">状态</label>
								<div class="col-sm-3">
									<select id="inputClassState" class="selectpicker show-tick" data-width="100%" name="state">
										<option value=""> </option>
										<option value="-1">全部</option>
										<!-- #for(Status st : classStatusList) -->
										<option value="${st.id}">${st.name}</option>
										<!-- #end -->
									</select>
								</div>
								<label for="inputMainTeacher" class="col-sm-1 control-label">老师</label>
								<div class="col-sm-3">
									<select id="inputMainTeacher" data-live-search="true"
										class="selectpicker show-tick" data-width="100%" name="mainTeacher">
										<option value=""> </option>
										<option value="0">全部</option>
										<!-- #for(Coach teacher : mainTeachers) -->
										<option value="${teacher.coachId}">${teacher.name}</option>
										<!-- #end -->
									</select>
								</div>
								
								<br /> <br />
								<label for="inputClassAssignedTo" class="col-sm-1 control-label">负责人</label>
								<div class="col-sm-3">
									<select id="inputClassAssignedTo" data-live-search="true"
										class="selectpicker show-tick" data-width="100%" name="assignedTo">
										<option value=""> </option>
										<option value="0">全部</option>
										<!-- #for(GroupUserModel um : assignedToList) -->
										<option value="${um.id}">${um.name}</option>
										<!-- #end -->
									</select>
								</div>
								<label for="inputPlacement" class="col-sm-1 control-label">场地</label>
								<div class="col-sm-3">
									<select id="inputPlacement" data-live-search="true"
										class="selectpicker show-tick" data-width="100%" name="placement">
										<option value=""> </option>
										<option value="0">全部</option>
										<!-- #for(Place place : plPlace) -->
										<option value="${place.id}">${place.name}</option>
										<!-- #end -->
									</select>
								</div>
								<br /> <br />
								<label for="inputClassType" class="col-sm-1 control-label">类型</label>
								<div class="col-sm-3">
									<select id="inputClassType" class="selectpicker show-tick" data-width="100%" name="classType">
										<option value=""> </option>
										<option value="" selected>全部</option>						
										<option value="不定会员">不定会员</option>
										<option value="固定会员">固定会员</option>
									</select>
								</div>
								<br /> <br /><br /> <br />
								<div style="display:none;">
								 <label for="txtClassStart"
										class="col-sm-1 control-label">有效日期</label>
									<div class="col-sm-3">
						                <div class='input-group date' id='txtClassStart' data-date-format="YYYY-MM-DD">
						                    <input id="startClassDate" name="startClassDate" type='text' class="form-control" value="${startClassDate}" />
						                    <span class="input-group-addon"><span class="glyphicon glyphicon-time"></span>
						                    </span>
						                </div>
									</div>
									<label for="txtClassEnd" class="panel-searh-zhi">至</label>
									<div class="col-sm-3">
						                <div class='input-group date' id='txtClassEnd' data-date-format="YYYY-MM-DD">
						                    <input id="endClassDate" name="endClassDate" type='text' class="form-control" value="${endClassDate}" />
						                    <span class="input-group-addon"><span class="glyphicon glyphicon-time"></span>
						                    </span>
						                </div>
									</div>
									</div>
								<input name="pageNo" id="hidPageNo" type="hidden" value="1">
								<input type="hidden" name="display" id="display" value="block"/>
								<div class="panel-db-search">
									<button id="btn_product_search" type="submit" class="btn btn-ade-default">搜索</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
		<div class="div_search_result clear">
			$!{include("class_list.html")}
		</div>
	</div>
</body>
<script type="text/javascript">
$(function(){
	$(".div_search_result").hide();
	var display = "${display}";
	if(display=='block'){
		$(".div_search_result").show();
	}else{
		$(".div_search_result").hide();
	}
	$("#txtClassStart").datetimepicker({
		language: "zh-CN",
		pickTime: false
	});
	
	$("#txtClassEnd").datetimepicker({
		language: "zh-CN",
		pickTime: false
	});
	
	$("#txtClassStart").on("dp.change", function(e) {
		$("#txtClassEnd").data("DateTimePicker").setMinDate(e.date);
	});

	$("#txtClassEnd").on("dp.change", function(e) {
		$("#txtClassStart").data("DateTimePicker").setMaxDate(e.date);
	});
	
	
});
</script>
</html>